"use strict";
cc._RF.push(module, '90891Bfh5JOEYGz5wDfImh+', 'DrawParabola');
// script/game/DrawParabola.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Constants_1 = require("../libs/Constants");
var GameEvent_1 = require("../libs/GameEvent");
var GameManager_1 = require("./GameManager");
var Stosh_1 = require("./Stosh");
// author : lamyoung
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var DrawParabola = /** @class */ (function (_super) {
    __extends(DrawParabola, _super);
    function DrawParabola() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.stosh = null;
        _this._graphic = null;
        _this._parabolaTrace = new Array();
        _this._linearVelocity = new cc.Vec2(0, 0);
        return _this;
    }
    DrawParabola.prototype.onLoad = function () {
        this._graphic = this.node.getComponent(cc.Graphics);
    };
    DrawParabola.prototype.onEnable = function () {
        GameEvent_1.GameEvent.on(Constants_1.default.StageEvent.DrawParabola, this.drawParabola, this);
        GameEvent_1.GameEvent.on(Constants_1.default.StageEvent.ClearParabola, this.clearParabola, this);
        GameEvent_1.GameEvent.on(Constants_1.default.StageEvent.CastStosh, this.castStosh, this);
    };
    DrawParabola.prototype.drawParabola = function (offset) {
        if (this._graphic) {
            this._graphic.clear();
            this._parabolaTrace = new Array();
            this._linearVelocity = new cc.Vec2(-offset.x * 10, Math.abs(offset.y) * 10);
            // console.log("当前偏移量", this._linearVelocity.x,this._linearVelocity.y)
            var dt = 0.05;
            for (var count = 0; count < 100; count++) {
                var time = dt * count;
                // s = v_x * t
                var dx = this._linearVelocity.x * time;
                // h = v_y * t + 0.5 * a * t * t
                var dy = this._linearVelocity.y * time - 500 * time * time;
                // 当前时间点坐标
                var targetX = dx;
                var targetY = dy + 100;
                this._parabolaTrace.push(new cc.Vec2(this.node.x + targetX, this.node.y + targetY));
                // 坐标超过地板就不画了
                if (targetY < 0)
                    break;
                this._graphic.circle(targetX, targetY, 8);
            }
            this._graphic.fill();
        }
    };
    DrawParabola.prototype.clearParabola = function () {
        if (this._graphic) {
            this._graphic.clear();
        }
    };
    DrawParabola.prototype.castStosh = function () {
        var stosh = cc.instantiate(this.stosh);
        stosh.setParent(GameManager_1.default.instace.stoshs);
        GameEvent_1.GameEvent.emit(Constants_1.default.StageEvent.ChangePlayerAni, Constants_1.default.PlayerAniState.stosh);
        stosh.getComponent(Stosh_1.default)._parabolaTrace = this._parabolaTrace;
    };
    DrawParabola.prototype.update = function () {
        if (GameManager_1.default.instace.gameIsStart && !GameManager_1.default.instace.gameIsOver) {
            this.node.setPosition(GameManager_1.default.instace.player.position);
        }
    };
    DrawParabola.prototype.onDisable = function () {
        GameEvent_1.GameEvent.off(Constants_1.default.StageEvent.DrawParabola, this.drawParabola, this);
        GameEvent_1.GameEvent.off(Constants_1.default.StageEvent.ClearParabola, this.clearParabola, this);
        GameEvent_1.GameEvent.off(Constants_1.default.StageEvent.CastStosh, this.castStosh, this);
    };
    __decorate([
        property(cc.Prefab)
    ], DrawParabola.prototype, "stosh", void 0);
    DrawParabola = __decorate([
        ccclass
    ], DrawParabola);
    return DrawParabola;
}(cc.Component));
exports.default = DrawParabola;

cc._RF.pop();